package com.acwing.partition21;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/6/3 10:11
 */
public class AC2004错字 {

    private static char[] str;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        str = reader.readLine().toCharArray();
        int l = 0, r = 0;
        for (int i = 0; i < str.length; i++) {
            if (str[i] == '(') l++;
            else r++;
        }
        int ans = 0;
        if (r > l) {
            int lc = 0, rc = 0;
            for (int i = 0; i < str.length; i++) {
                if (str[i] == '(') lc++;
                else {
                    rc++;
                    if (lc < rc) {
                        ans = rc;
                        break;
                    }
                }
            }
        } else if (l > r) {
            reverse();
            int lc = 0, rc = 0;
            for (int i = 0; i < str.length; i++) {
                if (str[i] == ')') rc++;
                else {
                    lc++;
                    if (lc > rc) {
                        ans = lc;
                        break;
                    }
                }
            }
        }
        writer.write(ans + "\n");
        writer.flush();
    }

    private static void reverse() {
        int l = 0, r = str.length - 1;
        while (l < r) {
            char t = str[l];
            str[l] = str[r];
            str[r] = t;
            l++; r--;
        }
    }
}
